home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / comm / tcp / Amster-main.lha / Amster_Install / Rexx / AmsterControl.amirx < prev    next >
Text File  |  2000-09-16  |  6KB  |  168 lines

  1. /*
  2. ** Amster Control Script For AmIRC
  3. ** $VER: AmsterControl.amirc 0.1 (15.9.2000)
  4. **
  5. ** By Roger Clark (kaedric@texas.net)
  6. ** September 15, 2000
  7. **
  8. ** Run this script from AmIRC's pulldown menu.  You can then send commands to
  9. ** the scripts Arexx port 'AMSTERCONTROL'.  The easiest way to do this is to
  10. ** set up an Alias in AmIRC:  /RX "Address 'AMSTERCONTROL' %p"
  11. **
  12. ** Commands: CONNECT, DISCONNECT, STATS, WHOIS {user}, SEARCH {string}, DOWNLOAD {file number}, QUIT
  13. **
  14. */
  15.  
  16. Options Results
  17.  
  18. Link.0  = "Unknown"
  19. Link.1  = "14.4K Modem"
  20. Link.2  = "28.8K Modem"
  21. Link.3  = "33.6K Modem"
  22. Link.4  = "56K Modem"
  23. Link.5  = "ISDN 64K"
  24. Link.6  = "ISDN 128K"
  25. Link.7  = "Cable"
  26. Link.8  = "DSL"
  27. Link.9  = "T1"
  28. Link.10 = "T3+"
  29.  
  30. If ~show('l','rexxsupport.library') then Do
  31.   If ~addlib('rexxsupport.library',0,-30,0) then Do
  32.     say "Couldn't access rexxsupport.library!"
  33.     Exit 5
  34.   End
  35. End
  36. If ~show('l','rexxarplib.library') then Do
  37.   If ~addlib('rexxarplib.library',0,-30,0) then Do
  38.     say "Couldn't access rexxarplib.library!"
  39.     Exit 5
  40.   End
  41. End
  42.  
  43. CreatePort:
  44.   MyPort = OpenPort("AMSTERCONTROL")
  45.   If MyPort = 0 Then Do
  46.     'Echo P='d2c(27)'b«Amster» Unable to create Arexx Port'
  47.     Exit
  48.   End
  49.   Else Do
  50.     'Echo P='d2c(27)'b«Amster» Amster Control is now active.'
  51.   End
  52.  
  53. WaitOnPort:
  54.   Call WaitPkt("AMSTERCONTROL")
  55.   Packet = GetPkt("AMSTERCONTROL")
  56.   If Packet = "00000000"x Then Signal WaitOnPort
  57.   Command = GetArg(Packet)
  58.  
  59. StartHere:
  60. If Show('P','AMSTER.1') Then Do
  61.   Select
  62.     When Upper(Command) = "STATS" Then Do
  63.       Address 'AMSTER.1' 'GETSERVERSTATS INFO'
  64.       If RC = 0 Then Do
  65.         Day = Date('N',INFO.CONNECTTIME % (60*60*24), 'I')
  66.         ElapSec = ((INFO.CONNECTTIME / (60*60*24)) - (INFO.CONNECTTIME % (60*60*24))) * 60 * 60 * 24 % 1
  67.         Hours = ElapSec % 3600
  68.         Minutes = (ElapSec % 60) - (Hours * 60)
  69.         Seconds = ElapSec - (Hours * 3600) - (Minutes * 60) + 1
  70.         OnlineTime = Hours":"Right("00"||Minutes,2)":"Right("00"||Seconds,2)
  71.         'Echo P='d2c(27)'b«Amster» 'INFO.SERVER':'INFO.PORT' (connected since 'OnlineTime')'
  72.         'Echo P='d2c(27)'b«Amster» 'INFO.SONGS' songs in 'INFO.USERS' libraries ('INFO.GIGABYTES' GB)'
  73.       End
  74.       Else If RC = 5 Then Do
  75.         'Echo P='d2c(27)'b«Amster» Not currently connected to a server.'
  76.       End
  77.     End
  78.     When Upper(Word(Command,1)) = "SEARCH" Then Do
  79.       'Echo P='d2c(27)'b«Amster» Searching for "'SubWord(Command,2)'"'
  80.       Address 'AMSTER.1' 'SEARCH "'SubWord(Command,2)'" SONG'
  81.       If SONG.COUNT > 0 Then Do
  82.         'Echo P='d2c(27)'b«Amster» Found 'SONG.COUNT' matches.'
  83.         Do Loop = 0 to SONG.COUNT - 1
  84.           Speed = SONG.Loop.LINK
  85.           Name = SubStr(SONG.Loop.TITLE,LastPos('\',SONG.Loop.TITLE) +1)
  86.           Minutes = (SONG.Loop.TIME % 60)
  87.           Seconds = SONG.Loop.TIME - (Minutes * 60)
  88.           PlayTime = Minutes":"Right("00"||Seconds,2)
  89.           'Echo P='d2c(27)'b«Amster» 'Loop': 'Name' ['Playtime'/'Link.Speed'/'SONG.Loop.BITRATE'kbps]'
  90.         End
  91.       End
  92.       Else Do
  93.         'Echo P='d2c(27)'b«Amster» No matches found.'
  94.       End
  95.     End
  96.     When Upper(Word(Command,1)) = "CONNECT" Then Do
  97.       'Echo P='d2c(27)'b«Amster» Connecting to new server'
  98.       Address 'AMSTER.1' 'CONNECT'
  99.       Call CheckOnline
  100.       Command = "STATS"
  101.       Signal StartHere
  102.     End
  103.     When Upper(Word(Command,1)) = "DISCONNECT" Then Do
  104.       'Echo P='d2c(27)'b«Amster» Disconnecting from server'
  105.       Address 'AMSTER.1' 'DISCONNECT'
  106.     End
  107.     When Upper(Word(Command,1)) = "WHOIS" Then Do
  108.       Address 'AMSTER.1' 'WHOIS 'Word(Command,2)' LUSER'
  109.       If RC = 0 Then Do
  110.         Speed = LUSER.LINK
  111.         Hours = LUSER.TIME % 3600
  112.         Minutes = (LUSER.TIME % 60) - (Hours * 60)
  113.         Seconds = LUSER.TIME - (Hours * 3600) - (Minutes * 60)
  114.         OnlineTime = Hours":"Right("00"||Minutes,2)":"Right("00"||Seconds,2)
  115.         'Echo P='d2c(27)'b«Amster» User: 'Luser.Nick' (level: 'Luser.Level') - online: 'OnlineTime' ('Luser.Status')'
  116.         If Luser.Channels ~= "" then 'Echo P='d2c(27)'b«Amster» Channels: 'Luser.Channels
  117.         'Echo P='d2c(27)'b«Amster» Shares: 'Luser.Shares', downloads: 'Luser.Downloads', uploads: 'Luser.Uploads
  118.         'Echo P='d2c(27)'b«Amster» Client: 'Luser.Client', link: 'Link.Speed
  119.       End
  120.       Else If RC = 1 Then Do
  121.         Logoff = Date('N',LUSER.LASTSEEN % (60*60*24), 'I')
  122.         ElapSec = ((LUSER.LASTSEEN / (60*60*24)) - (LUSER.LASTSEEN % (60*60*24))) * 60 * 60 * 24 % 1
  123.         Hours = ElapSec % 3600
  124.         Minutes = (ElapSec % 60) - (Hours * 60)
  125.         Seconds = ElapSec - (Hours * 3600) - (Minutes * 60)
  126.         OfflineTime = Hours":"Right("00"||Minutes,2)":"Right("00"||Seconds,2)
  127.         'Echo P='d2c(27)'b«Amster» User: 'Luser.Nick' (level: 'Luser.Level') - last seen 'Logoff' 'OfflineTime
  128.       End
  129.       Else Do
  130.         'Echo P='d2c(27)'b«Amster» 'd2c(2)'Error: 'd2c(2)||Word(Command,2)' is not a known user'
  131.       End
  132.     End
  133.     When Upper(Word(Command,1)) = "DOWNLOAD" Then Do
  134.       Choice = Word(Command,2)
  135.       If Choice < 0 | Choice > SONG.COUNT Then Do
  136.         'Echo P='d2c(27)'b«Amster» Invalid selection.'
  137.       End
  138.       Else Do
  139.         Name = SubStr(SONG.Choice.TITLE,LastPos('\',SONG.Choice.TITLE) +1)
  140.         'Echo P='d2c(27)'b«Amster» Downloading 'Name
  141.         Address 'AMSTER.1' 'DOWNLOAD 'Choice
  142.       End
  143.     End
  144.     When Upper(Command) = "QUIT" Then Do
  145.       'Echo P='d2c(27)'b«Amster» Control script is exiting.'
  146.       Reply(Packet,0)
  147.       Call ClosePort("AMSTERCONTROL")
  148.       Exit
  149.     End
  150.     Otherwise 'Echo P='d2c(27)'b«Amster» Available commands: CONNECT, DISCONNECT, STATS, WHOIS {user}, SEARCH {string}, DOWNLOAD {file number}, QUIT'
  151.   End
  152. End
  153. Reply(Packet,0)
  154. Signal WaitOnPort
  155.  
  156. CheckOnline:
  157.   If Show('P','AMSTER.1') = 0 then Do
  158.     'Echo P='d2c(27)'b«Amster» Could not locate Amster''s Arexx port.'
  159.   End
  160.   Address 'AMSTER.1' 'ISONLINE'
  161.   If RC = 0 then Do
  162.     Do While RC = 0
  163.       Call Delay(50)
  164.       Address 'AMSTER.1' 'ISONLINE'
  165.     End
  166.   End
  167.   Return
  168.